import Redis from "ioredis";

export default class RedisWrapper {
    private _client: Redis;
    constructor(options) {
        this._client = new Redis(options); // 初始化Redis客户端
        this._client.ping(()=>{
            console.log('redis连接成功');
        })
    }

    get(key) {
        return new Promise((resolve, reject) => {
            this._client.get(key, (err, reply) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(reply);
                }
            });
        });
    }

    set(key, value) {
        return new Promise((resolve, reject) => {
            this._client.set(key, value, (err, reply) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(true);
                }
            });
        });
    }
    remove(key){
        return new Promise((resolve, reject) => {
            this._client.del(key, (err, reply) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(true);
                }
            });
        });
    }
}

 exports = RedisWrapper;